package com.dao.impl;

import com.Bean.Client;
import com.dao.ClientDao;
import com.util.JdbcUtil;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class ClientDaoimpl implements ClientDao {

    @Override
    public int insert(Client client) throws SQLException {
        String sql =   "insert into client(pno,pphone,pname,pgender,pbrithday,cli_pid,pid,pcretime,ptotal,pcount) VALUES (?,?,?,?,?,?,?,?,0,0)";



        return JdbcUtil.insertOrUpdateOrDelete(sql, new Object[]{
                client.getPno(),client.getPphone(),
                client.getPname(), client.getPgender(), client.getPbrithday(),
                client.getCliPid(),client.getPid(),new Date()});
    }

    @Override
    public List<Client> queryData(Client client) throws IllegalAccessException, SQLException, InstantiationException {
        return null;
    }

    @Override
    public int update(Client client) throws SQLException {

        String sql = "update client set cli_pid='5' where pid=? ";

        return JdbcUtil.insertOrUpdateOrDelete(sql,new Object[]{client.getPid()});
    }

    @Override
    public int deleteById(Object id) throws SQLException {
        return 0;
    }



    @Override
    public int updateclient(Client client) throws SQLException {

        String sql = "update client set pname=?,pgender=?,pbrithday=?,pid=? where pphone =?";

        return JdbcUtil.insertOrUpdateOrDelete(sql,new Object[]{client.getPname(),client.getPgender(),
        client.getPbrithday(),client.getPid(),client.getPphone()});
    }

    @Override
    public int blankUpdate(Client client) throws SQLException {

        //update client set cli_pid='1' where pid='111111111111123'

        String sql = "update client set cli_pid='1' where pid=? ";


                return JdbcUtil.insertOrUpdateOrDelete(sql,new Object[]{client.getPid()});
    }


}
